import lejos.nxt.LCD;
import lejos.nxt.UltrasonicSensor;
import lejos.robotics.subsumption.Behavior;


public class LeftSonarBehaviour implements Behavior 
{


	private UltrasonicSensor leftSonar;
//	private UltrasonicSensor rightSonar;
	private MapMaker mm = null;

	public LeftSonarBehaviour(MapMaker mm)
	{
		this.mm = mm;
//		this.rightSonar = mm.rightSonar;
		this.leftSonar = mm.leftSonar;    
	}
	
	@Override
	public boolean takeControl() 
	{ 		
		leftSonar.ping(); //rightSonar.ping(); 
		return leftSonar.getDistance() < 30; // || rightSonar.getDistance() < 15; 	
	}

	@Override
	public void suppress() 
	{  
		mm.snav.stop();
	}

	@Override
	public void action() {

		mm.snav.rotate(-10);  
		mm.snav.stop();
		mm.snav.forward();
		
		
		do	{ mm.UpdatePose(); }	while( mm.snav.isMoving() );
		
		//try { Thread.sleep(100); } catch (InterruptedException e) {	}
	}


}
